package hw2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class Main
{
	public static void main(String[] args)
	{
		String trainingInputFilename = "DataforAssignment3/Training_1A.txt";
		String testInputFilename = "DataforAssignment3/Testing_1A.txt";
		
		System.out.println("Reading data from file " + trainingInputFilename);
		System.out.println("Reading data from file " + testInputFilename);
		InputStream trainingInputStream, testInputStream;
		try
		{
			trainingInputStream = new FileInputStream(trainingInputFilename);
			testInputStream = new FileInputStream(testInputFilename);
		}
		catch (FileNotFoundException e)
		{
			System.out.println("AGH I'm dead!");
			return;
		}
		
		TestFileReader fileReader = new TestFileReader();
		String trainingInputString = fileReader.parse(",", trainingInputStream);
		String testInputString = fileReader.parse(",", testInputStream); 
		
		//System.out.println("Training string: " + trainingInputString);
		//System.out.println("Test string:     " + testInputString);
		Learner unigramLearner = new Learner();
		Learner bigramLearner = new Learner();
		Learner trigramLearner = new Learner();
		unigramLearner.train(trainingInputString);
		bigramLearner.train(trainingInputString);
		trigramLearner.train(trainingInputString);
		
		System.out.println("Doing the majority class warmup...");
		double unigramResult = unigramLearner.unigramTest(testInputString, false);
		System.out.println("Unigram result: " + unigramResult);
		unigramLearner.unigramTestRandom();
		
		System.out.println("Doing a bigram learning model...");
		double bigramResult = bigramLearner.bigramTest(testInputString, false);
		System.out.println("Bigram result: " + bigramResult);
		bigramLearner.bigramTestRandom();
		
		System.out.println("Doing a trigram learning model...");
		double trigramResult = trigramLearner.trigramTest(testInputString, false);
		System.out.println("Trigram result: " + trigramResult);
		trigramLearner.trigramTestRandom();
		
		System.out.println("Doing a crossover...");
		
		crossOver co1 = new crossOver();
		Learner bestLearner = co1.getBestMethod(trainingInputString);
		double bestResult;
		if (bestLearner.getBestMethod() == 1)
		{
			bestResult = bestLearner.unigramTest(testInputString, false);
			System.out.println("Best Method: Unigram");
		}
		else if (bestLearner.getBestMethod() == 2)
		{
			bestResult = bestLearner.bigramTest(testInputString, false);
			System.out.println("Best Method: Bigram");
		}
		else
		{
			bestResult = bestLearner.trigramTest(testInputString, false);
			System.out.println("Best Method: Trigram");
		}
		System.out.println("Best method result: " + bestResult);
	}
}
